package cl.mt.mvc.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cl.mt.dto.DTOUsuario;
import cl.mt.mvc.helper.UsuarioHelper;

public class LogoffAction extends Action {

	private Logger log = LogManager.getLogger(LogoffAction.class.getName());

	public ActionForward execute(ActionMapping mapping, ActionForm form,

	HttpServletRequest request, HttpServletResponse response) {

		UsuarioHelper userHelper = new UsuarioHelper();
		DTOUsuario dtoUser = userHelper.getUserConectado(request);
		if (dtoUser != null) {
			log.debug("Logoff Usuario [" + dtoUser.getUsername() + "]");
		}

		request.getSession().invalidate();
		return mapping.findForward("SUCCESS");

	}

}